package com.xmh.ssm.other;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.junit.Test;

import com.xmh.ssm.utils.FileUtil;

public class XmlRead {

	@SuppressWarnings("unchecked")
	@Test
	public void test1() throws DocumentException {
		String path = "D:\\workShenzhen\\ssdev-platform\\src\\main\\java\\chis\\application\\hy\\schemas\\MDC_HypertensionVisit.sc";

		String fileStr = FileUtil.getFileStr(path);

		Element rootElement = (Element) DocumentHelper.parseText(fileStr).getRootElement();

		List<Element> elements = rootElement.elements("item");

		for (Element element : elements) {
			String id = element.attributeValue("id");
			if (StringUtils.isNotEmpty(id)) {
				System.out.println("a." + id + " as " + id + ",");
			} else {
				String ref = element.attributeValue("ref");
				System.out.println(ref + " as " + ref.split("\\.")[1] + ",");
			}
		}
	}

}
